import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'messages_all.dart';

/*
// 通过localization_intl.dart 生成intl_message.arb arb文件
flutter pub pub run intl_translation:extract_to_arb --output-dir=l10n-arb  lib/l10n/localization_intl.dart
// 通过arb文件生成对应的dart文件
flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/l10n/localization_intl.dart l10n-arb/intl_*.arb
// 也可以将上述两条指令写成脚本文件，intl.sh方便操作
// chmod +x intl.sh
// ./intl.sh

*/
class MyLocalizations {
  static get title {
    return Intl.message("hello word",
        name: "title", desc: "Title for the application");
  }

  String get tabHome {
    return Intl.message(
      'Home',
      name: 'tabHome',
      desc: '',
      args: [],
    );
  }

  String get tabProject {
    return Intl.message(
      'Project',
      name: 'tabProject',
      desc: '',
      args: [],
    );
  }

  String get tabWechatAccount {
    return Intl.message(
      'WechatAccount',
      name: 'tabWechatAccount',
      desc: '',
      args: [],
    );
  }

  String get tabStructure {
    return Intl.message(
      'Structure',
      name: 'tabStructure',
      desc: '',
      args: [],
    );
  }

  String get tabUser {
    return Intl.message(
      'User',
      name: 'tabUser',
      desc: '',
      args: [],
    );
  }

  String get actionConfirm {
    return Intl.message(
      'Confirm',
      name: 'actionConfirm',
      desc: '',
      args: [],
    );
  }

  String get actionCancel {
    return Intl.message(
      'Cancel',
      name: 'actionCancel',
      desc: '',
      args: [],
    );
  }

  static const MyLocalizationsDelegate delegate = MyLocalizationsDelegate();

  static Future<MyLocalizations> load(Locale locale) {
    final String name =
        locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
    final String localeName = Intl.canonicalizedLocale(name);
    return initializeMessages(localeName).then((b) {
      Intl.defaultLocale = localeName;
      return MyLocalizations();
    });
  }

  static MyLocalizations of(BuildContext context) {
    return Localizations.of<MyLocalizations>(context, MyLocalizations);
  }
}

class MyLocalizationsDelegate extends LocalizationsDelegate<MyLocalizations> {
  const MyLocalizationsDelegate();

  List<Locale> get supportedLocales {
    return const <Locale>[
      Locale('zh', ''),
      Locale('en', ''),
    ];
  }

  @override
  bool isSupported(Locale locale) => ['en', 'zh'].contains(locale.languageCode);

  @override
  Future<MyLocalizations> load(Locale locale) {
    return MyLocalizations.load(locale);
  }

  @override
  bool shouldReload(MyLocalizationsDelegate delegate) => false;
}
